// 导入 pinia
import { defineStore } from 'pinia'
// 导入 api
import {getClassify,getClassifyList,getClassificationList} from '@/api/classify'
// 创建pinia实例
export const usrClassifyInfo = defineStore('usrClassify', {
  state: () => ({
    getClassifyInfo: {},
    categoryItems: {}
  }),
  actions: {
    async getClassifyList() {
      try {
        // 发送请求
        const result = await getClassify()
        this.getClassifyInfo = result
      } catch (error) {
        console.log('请求失败', error)
      }
    },
     async getClassifyListInfo(id:number) {
      try {
        // 发送请求
        const result = await getClassifyList(id)
        this.getClassifyInfo = result
      } catch (error) {
        console.log('请求失败', error)
      }
    },
    async getClassification(subCategoryId:any,categoryId:any) {
      try {
        // 发送请求
        const result = await getClassificationList(subCategoryId,categoryId)
        console.log(result)
        this.categoryItems = result.categoryItems
      } catch (error) {
        console.log('请求失败', error)
      }
    }
  },
  getters: {
    // 导航栏
    categoryL1List(state){
      return state.getClassifyInfo?.categoryL1List
    },
    // 右侧图片
    picUrl(state){
      return state.getClassifyInfo?.currentCategory?.bannerList[0].picUrl
    },
    // 推荐右侧数据
     categoryList(state){
      return state.getClassifyInfo.categoryGroupList
     },
     itemList(state){
      return state.categoryItems.itemList
     }
  }
})
